<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Dc (computer program)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Dc_(computer_program)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.math.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Dc_computer_program rootpage-Dc_computer_program skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main">dc (computer program)</span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1295905060">
/* start https://en.wikipedia.org/ */
.mw-parser-output .infobox-subbox{padding:0;border:none;margin:-3px;width:auto;min-width:100%;font-size:100%;clear:none;float:none;background-color:transparent}.mw-parser-output .infobox-3cols-child{margin:auto}.mw-parser-output .infobox .navbar{font-size:100%}@media screen{html.skin-theme-clientpref-night .mw-parser-output .infobox-full-data:not(.notheme)>div:not(.notheme)[style]{background:#1f1f23!important;color:#f8f9fa}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .infobox-full-data:not(.notheme)>div:not(.notheme)[style]{background:#1f1f23!important;color:#f8f9fa}}@media(min-width:640px){body.skin--responsive .mw-parser-output .infobox-table{display:table!important}body.skin--responsive .mw-parser-output .infobox-table>caption{display:table-caption!important}body.skin--responsive .mw-parser-output .infobox-table>tbody{display:table-row-group}body.skin--responsive .mw-parser-output .infobox-table th,body.skin--responsive .mw-parser-output .infobox-table td{padding-left:inherit;padding-right:inherit}}
/* end https://en.wikipedia.org/ */
</style><table class="infobox vevent"><tbody><tr><th colspan="2" class="infobox-above summary">dc</th></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Programmer" title="Programmer">Original author(s)</a></th><td class="infobox-data"><a href="Lorinda_Cherry" title="Lorinda Cherry">Lorinda Cherry</a>, <a href="Robert_Morris_(cryptographer)" title="Robert Morris (cryptographer)">Robert Morris</a><br>(<a href="AT%26T_Bell_Laboratories" class="mw-redirect" title="AT&T Bell Laboratories">AT&T Bell Laboratories</a>)</td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Programmer" title="Programmer">Developer(s)</a></th><td class="infobox-data">Various <a href="Open-source_software" title="Open-source software">open-source</a> and <a href="Commercial_software" title="Commercial software">commercial</a> developers</td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;">Written in</th><td class="infobox-data"><a href="B_(programming_language)" title="B (programming language)">B</a></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Operating_system" title="Operating system">Operating system</a></th><td class="infobox-data"><a href="Unix" title="Unix">Unix</a>, <a href="Unix-like" title="Unix-like">Unix-like</a>, <a href="Plan_9_from_Bell_Labs" title="Plan 9 from Bell Labs">Plan 9</a></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Computing_platform" title="Computing platform">Platform</a></th><td class="infobox-data"><a href="Cross-platform" class="mw-redirect" title="Cross-platform">Cross-platform</a></td></tr><tr><th scope="row" class="infobox-label" style="white-space: nowrap;"><a href="Software_categories#Categorization_approaches" title="Software categories">Type</a></th><td class="infobox-data"><a href="Command_(computing)" title="Command (computing)">Command</a></td></tr></tbody></table>
<p><b>dc</b> (<i>desk calculator</i>) is a <a href="Cross-platform" class="mw-redirect" title="Cross-platform">cross-platform</a> <a href="Reverse_Polish_notation" title="Reverse Polish notation">reverse-Polish</a> calculator which supports <a href="Arbitrary-precision_arithmetic" title="Arbitrary-precision arithmetic">arbitrary-precision arithmetic</a>.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> It was written by <a href="Lorinda_Cherry" title="Lorinda Cherry">Lorinda Cherry</a> and <a href="Robert_Morris_(cryptographer)" title="Robert Morris (cryptographer)">Robert Morris</a> at <a href="Bell_Labs" title="Bell Labs">Bell Labs</a>.<sup id="cite_ref-reader_2-0" class="reference"><a href="#cite_note-reader-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> It is one of the oldest <a href="Unix" title="Unix">Unix</a> utilities, preceding even the invention of the <a href="C_(programming_language)" title="C (programming language)">C programming language</a>. Like other utilities of that vintage, it has a powerful set of features but terse syntax.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
Traditionally, the <a href="Bc_(programming_language)" title="Bc (programming language)">bc</a> calculator program (with <a href="Infix_notation" title="Infix notation">infix notation</a>) was implemented on top of dc, now the implementation of GNU dc bases on bc.<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
</p><p>This article provides some examples in an attempt to give a general flavour of the language; for a complete list of commands and syntax, one should consult the <a href="Man_page" title="Man page">man page</a> for one's specific implementation.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="History">History</h2></div>
<p>dc is the oldest surviving <a href="Unix" title="Unix">Unix</a> language program. When its home <a href="Bell_Labs" title="Bell Labs">Bell Labs</a> received a <a href="PDP-11" title="PDP-11">PDP-11</a>, dc—written in <a href="B_(programming_language)" title="B (programming language)">B</a>—was the first language to run on the new computer, even before an assembler.<sup id="cite_ref-reader_2-1" class="reference"><a href="#cite_note-reader-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> <a href="Ken_Thompson" title="Ken Thompson">Ken Thompson</a> has opined that dc was the very first program written on the machine.<sup id="cite_ref-KenThompson_6-0" class="reference"><a href="#cite_note-KenThompson-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Basic_operations">Basic operations</h2></div>
<p>To multiply four and five in dc (note that most of the <a href="Whitespace_character" title="Whitespace character">whitespace</a> is optional):
</p>
<div class="mw-highlight mw-highlight-lang-console mw-content-ltr" dir="ltr"><pre><span class="gp">$ </span>cat<span class="w"> </span><<<span class="w"> </span>EOF<span class="w"> </span>><span class="w"> </span>cal.txt
<span class="go">4 5 *</span>
<span class="go">p</span>
<span class="go">EOF</span>
<span class="gp">$ </span>dc<span class="w"> </span>cal.txt
<span class="go">20</span>
<span class="gp">$</span>
</pre></div>
<p>The results are also available from the commands:
</p>
<div class="mw-highlight mw-highlight-lang-console mw-content-ltr" dir="ltr"><pre><span class="gp">$ </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"4 5 * p"</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>dc
</pre></div>
<p>or
</p>
<div class="mw-highlight mw-highlight-lang-console mw-content-ltr" dir="ltr"><pre><span class="gp">$ </span>dc<span class="w"> </span>-
<span class="go">4 5*pq</span>
<span class="go">20</span>
<span class="gp">$ </span>dc
<span class="go">4 5 *</span>
<span class="go">p</span>
<span class="go">20</span>
<span class="go">q</span>
<span class="gp">$ </span>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'4 5 * p'</span>
</pre></div>
<p>This translates into "push four and five onto the stack, then, with the multiplication operator, pop two elements from the stack, multiply them and push the result onto the stack." Then the <code>p</code> command is used to examine (print out to the screen) the top element on the stack. The <code>q</code> command quits the invoked instance of dc. Note that numbers must be spaced from each other even as some operators need not be.
</p><p>The <a href="Arithmetic_precision" class="mw-redirect" title="Arithmetic precision">arithmetic precision</a> is changed with the command <code>k</code>, which sets the number of fractional digits (the number of digits following the <a href="Radix_point" class="mw-redirect" title="Radix point">point</a>) to be used for arithmetic operations. Since the default precision is zero, this sequence of commands produces <code>0</code> as a result:
</p>
<pre>2 3 / p
</pre>
<p>By adjusting the precision with <code>k</code>, an arbitrary number of decimal places can be produced. This command sequence outputs <code>.66666</code>.
</p>
<pre>5 k
2 3 / p
</pre>
<p>To evaluate <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\sqrt {\left(12+\left(-3\right)^{4}\right) \over 11}}-22}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mfrac>
<mrow>
<mo>(</mo>
<mrow>
<mn>12</mn>
<mo>+</mo>
<msup>
<mrow>
<mo>(</mo>
<mrow>
<mo>−<!-- − --></mo>
<mn>3</mn>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>4</mn>
</mrow>
</msup>
</mrow>
<mo>)</mo>
</mrow>
<mn>11</mn>
</mfrac>
</msqrt>
</mrow>
<mo>−<!-- − --></mo>
<mn>22</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\sqrt {\left(12+\left(-3\right)^{4}\right) \over 11}}-22}</annotation>
</semantics>
</math></span><img src="./87d86498eee6f8a2b1148e2978cb2aa3b16e8fdb.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:22.23ex; height:8.176ex;" alt="{\displaystyle {\sqrt {\left(12+\left(-3\right)^{4}\right) \over 11}}-22}" loading="lazy"></span>: (<code>v</code> computes the square root of the top of the stack and <code>_</code> is used to input a negative number):
</p>
<pre>12 _3 4 ^ + 11 / v 22 -
p
</pre>
<p>To swap the top two elements of the stack, use the <code>r</code> command. To duplicate the top element, use the <code>d</code> command.
</p>
<div class="mw-heading mw-heading2"><h2 id="Input/output">Input/output</h2></div>
<p>To read a line from <a href="Stdin" class="mw-redirect" title="Stdin">stdin</a>, use the <code>?</code> command. This evaluates the line as if it were a dc command, and so it is necessary that it be syntactically correct and presents a potential security problem because the <code>!</code> dc command enables arbitrary command execution.
</p><p>As mentioned above, <code>p</code> prints the top of the stack with a newline after it. <code>n</code> pops the top of the stack and prints it without a trailing newline. <code>f</code> prints the entire stack with one entry per line.
</p><p>dc also supports arbitrary input and output <a href="Radix" title="Radix">radices</a>. The <code>i</code> command pops the top of the stack and uses it for the input base. Hex digits must be in upper case to avoid collisions with dc commands and are limited to A-F. The <code>o</code> command does the same for the output base, but keep in mind that the input base affects the parsing of every numeric value afterwards so it is usually advisable to set the output base first. Therefore <code>10o</code> sets the output radix to the current input radix, but generally not to 10 (ten). Nevertheless <code>Ao</code> resets the output base to 10 (ten), regardless of the input base. To read the values, the <code>K</code>, <code>I</code> and <code>O</code> commands push the current precision, input radix and output radix on to the top of the stack.
</p><p>As an example, to convert from hex to binary:
</p>
<div class="mw-highlight mw-highlight-lang-console mw-content-ltr" dir="ltr"><pre><span class="gp">$ </span><span class="nb">echo</span><span class="w"> </span>16i2o<span class="w"> </span>DEADBEEFp<span class="w"> </span><span class="p">|</span><span class="w"> </span>dc
<span class="go">11011110101011011011111011101111</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Language_features">Language features</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Registers">Registers</h3></div>
<p>In addition to these basic arithmetic and stack operations, dc includes support for <a href="Macro_(computer_science)" title="Macro (computer science)">macros</a>, conditionals and storing of results for later retrieval.
</p><p>The mechanism underlying macros and conditionals is the <b>register</b>, which in dc is a storage location with a single character name which can be stored to and retrieved from: <code>sc</code> pops the top of the stack and stores it in register c, and <code>lc</code> pushes the value of register c onto the stack. For example:
</p>
<pre>3 sc 4 lc * p
</pre>
<p>Registers can also be treated as secondary stacks, so values can be pushed and popped between them and the main stack using the <code>S</code> and <code>L</code> commands.
</p>
<div class="mw-heading mw-heading3"><h3 id="Strings">Strings</h3></div>
<p>String values are enclosed in <code>[</code> and <code>]</code> characters and may be pushed onto the stack and stored in registers. The <code>a</code> command converts the low order byte of the numeric value into an <a href="ASCII#ASCII_printable_characters" title="ASCII">ASCII</a> character, or if the top of the stack is a string it replaces it with the first character of the string. There are no ways to build up strings or perform string manipulation other than executing it with the <code>x</code> command, or printing it with the <code>P</code> command.
</p><p>The <code>#</code> character begins a comment to the end of the line.
</p>
<div class="mw-heading mw-heading3"><h3 id="Macros">Macros</h3></div>
<p>Macros are then implemented by allowing registers and stack entries to be strings as well as numbers. A string can be printed, but it can also be executed (i.e. processed as a sequence of dc commands). So for instance we can store a macro to add one and then multiply by 2 into register m:
</p>
<pre>[1 + 2 *] sm
</pre>
<p>and then (using the <code>x</code> command which executes the top of the stack) we can use it like this:
</p>
<pre>3 lm x p
</pre>
<div class="mw-heading mw-heading3"><h3 id="Conditionals">Conditionals</h3></div>
<p>Finally, we can use this macro mechanism to provide conditionals. The command <code>=r</code> pops two values from the stack, and executes the macro stored in register <code>r</code> only if they are equal. So this prints the string <code>equal</code> only if the top two values on the stack are of equal value:
</p>
<pre>[[equal]p] sr 5 5 =r
</pre>
<p>Other conditionals are <code>></code>, <code>!></code>, <code><</code>, <code>!<</code>, <code>!=</code>, which execute the specified macro if the top two values on the stack are greater, less than or equal to ("not greater"), less than, greater than or equal to ("not less than"), and not equals, respectively. Note that the order of the operands in inequality comparisons is the opposite of the order for arithmetic; <style data-mw-deduplicate="TemplateStyles:r1239335663">
/* start https://en.wikipedia.org/ */
.mw-parser-output .mw-tmpl-kbd{background:#EEE;color:var(--color-base)}@media screen{html.skin-theme-clientpref-night .mw-parser-output .mw-tmpl-kbd{background:#171a1d}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .mw-tmpl-kbd{background:#171a1d}}
/* end https://en.wikipedia.org/ */
</style><kbd class="mw-tmpl-kbd" style="letter-spacing:0.05em; padding-left:0.25em; padding-right:0.2em;">5 3 -</kbd> evaluates to <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">5 - 3 = 2</code>, but <kbd class="mw-tmpl-kbd" style="letter-spacing:0.05em; padding-left:0.25em; padding-right:0.2em;">5 3 <t</kbd> runs the contents of the <kbd class="mw-tmpl-kbd" style="letter-spacing:0.05em; padding-left:0.25em; padding-right:0.2em;">t</kbd> register because <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">3 < 5</code>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Loops">Loops</h3></div>
<p>Looping is then possible by defining a macro which (conditionally) reinvokes itself. A simple factorial of the top of the stack might be implemented as:
</p>
<pre># F(x): return x!
# if x-1 > 1
# return x * F(x-1)
# otherwise
# return x
[d1-d1<F*]dsFxp
</pre>
<p>The <code>1Q</code> command exits from a macro, allowing an early return. <code>q</code> quits from two levels of macros (and dc itself if there are less than two levels on the call stack). <code>z</code> pushes the current stack depth before the <code>z</code> operation.
</p>
<div class="mw-heading mw-heading2"><h2 id="Examples">Examples</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Summing_the_entire_stack">Summing the entire stack</h3></div>
<p>This is implemented with a macro stored in register <code>a</code> which conditionally calls itself, performing an addition each time, until only one value remains on the stack. The <code>z</code> operator is used to push the number of entries in the stack onto the stack. The comparison operator <code>></code> pops two values off the stack in making the comparison.
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s2">"1 2 4 8 16 100 0d[+z1<a]dsaxp"</span>
</pre></div>
<p>And the result is 131.
</p>
<div class="mw-heading mw-heading3"><h3 id="Summing_all_dc_expressions_as_lines_from_file">Summing all dc expressions as lines from file</h3></div>
<p>A bare number is a valid dc expression, so this can be used to sum a file where each line contains a single number.
</p><p>This is again implemented with a macro stored in register <code>a</code> which conditionally calls itself, performing an addition each time, until only one value remains on the stack.
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s2">"0d[?+z1<a]dsaxp"</span><span class="w"> </span><<span class="w"> </span>file
</pre></div>
<p>The <code>?</code> operator reads another command from the input stream. If the input line contains a decimal number, that value is added to the stack. When the input file reaches end of file, the command is null, and no value is added to the stack.
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span class="o">{</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"5"</span><span class="p">;</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"7"</span><span class="p">;</span><span class="w"> </span><span class="o">}</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>dc<span class="w"> </span>-e<span class="w"> </span><span class="s2">"0d[?+z1<a]dsaxp"</span>
</pre></div>
<p>And the result is 12.
</p><p>The input lines can also be complex dc commands.
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre><span class="o">{</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"3 5 *"</span><span class="p">;</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"4 3 *"</span><span class="p">;</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"5dd++"</span><span class="p">;</span><span class="w"> </span><span class="o">}</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>dc<span class="w"> </span>-e<span class="w"> </span><span class="s2">"0d[?+z1<a]dsaxp"</span>
</pre></div>
<p>And the result is 42.
</p><p>Note that since dc supports arbitrary precision, there is no concern about numeric overflow or loss of precision, no matter how many lines the input stream contains, unlike a similarly concise solution in <a href="AWK" title="AWK">AWK</a>.
</p><p>Downsides of this solution are: the loop stops on encountering a blank line in the input stream (technically, any input line which does not add at least one numeric value to the stack); and, for handling negative numbers, leading instances of '-' to denote a negative sign must be change to '_' in the input stream, because of dc's nonstandard negative sign. The <code>?</code> operator in dc does not provide a clean way to discern reading a blank line from reading end of file.
</p>
<div class="mw-heading mw-heading3"><h3 id="Unit_conversion">Unit conversion</h3></div>
<p>As an example of a relatively simple program in dc, this command (in 1 line):
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'[[Enter a number (metres), or 0 to exit]PAP]sh[q]sz[lhx?d0=zAk.0254/.5+0kC~1/rn[ feet ]Pn[ inches]PAPdx]dx'</span>
</pre></div>
<p>converts distances from metres to feet and inches; the bulk of it is concerned with prompting for input, printing output in a suitable format and looping around to convert another number.
</p>
<div class="mw-heading mw-heading3"><h3 id="Greatest_common_divisor">Greatest common divisor</h3></div>
<p>As an example, here is an implementation of the <a href="Euclidean_algorithm" title="Euclidean algorithm">Euclidean algorithm</a> to find the <a href="Greatest_common_divisor" title="Greatest common divisor">GCD</a>:
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'??[dSarLa%d0<a]dsax+p'</span><span class="w"> </span><span class="c1"># shortest</span>
dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'[a=]P?[b=]P?[dSarLa%d0<a]dsax+[GCD:]Pp'</span><span class="w"> </span><span class="c1"># easier-to-read version</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Factorial">Factorial</h3></div>
<p>Computing the <a href="Factorial" title="Factorial">factorial</a> of an input value, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n!=\prod _{i=1}^{n}i}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
<mo>!</mo>
<mo>=</mo>
<munderover>
<mo>∏<!-- ∏ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
</mrow>
</munderover>
<mi>i</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n!=\prod _{i=1}^{n}i}</annotation>
</semantics>
</math></span><img src="./ece82c3b0fa93f49025e38f8377e90e76d1bedf6.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.005ex; width:9.299ex; height:6.843ex;" alt="{\displaystyle n!=\prod _{i=1}^{n}i}" loading="lazy"></span>
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'?[q]sQ[d1=Qd1-lFx*]dsFxp'</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Quines_in_dc">Quines in dc</h3></div>
<p>There exist also <a href="Quine_(computing)" title="Quine (computing)">quines</a> in the programming language dc; programs that produce its source code as output.
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'[91Pn[dx]93Pn]dx'</span>
dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'[91PP93P[dx]P]dx'</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Printing_all_prime_numbers">Printing all prime numbers</h3></div>
<div class="mw-highlight mw-highlight-lang-sh mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'2p3p[dl!d2+s!%0=@l!l^!<#]s#[s/0ds^]s@[p]s&[ddvs^3s!l#x0<&2+l.x]ds.x'</span>
</pre></div>
<p>This program was written by Michel Charpentier.
It outputs the sequence of prime numbers.
Note that shorter implementation is possible, which needs fourteen symbols fewer.
</p>
<div class="mw-highlight mw-highlight-lang-sh mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'2p3p[pq]s$[l!2+ds!l^<$dl!%0<#]s#[+dvs^1s!l#x2l.x]ds.x'</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Integer_factorization">Integer factorization</h3></div>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'[n=]P?[p]s2[lip/dli%0=1dvsr]s12sid2%0=13sidvsr[dli%0=1lrli2+dsi!>.]ds.xd1<2'</span>
</pre></div>
<p>This program was also written by Michel Charpentier.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>
</p><p>There is a shorter
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s2">"[n=]P?[lfp/dlf%0=Fdvsr]sF[dsf]sJdvsr2sf[dlf%0=Flfdd2%+1+sflr<Jd1<M]dsMx"</span>
</pre></div>
<p>and a faster solution (try with the 200-bit number <span class="texhtml">2<sup>200</sup>-1</span> (input <code>2 200^1-</code>)
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s2">"[n=]P?[lfp/dlf% 0=Fdvsr]sFdvsr2sfd2%0=F3sfd3%0=F5sf[dlf%0=Flfd4+sflr>M]sN[dlf%0=Flfd2+sflr>N]dsMx[p]sMd1<M"</span>
</pre></div>
<p>Note that the latter can be sped up even more, if the access to a constant is replaced by a register access.
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s2">"[n=]P?[lfp/dlf%l0=Fdvsr]sF2s2dvsr2sf4s4d2%0=F3sfd3%0=F5sf[dlf%l0=Flfdl4+sflr>M]sN[dlf%l0=Flfdl2+sflr>N]dsMx[p]sMd1<M"</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Calculating_Pi">Calculating Pi</h3></div>
<p>An implementation of the <a href="Chudnovsky_algorithm" title="Chudnovsky algorithm">Chudnovsky algorithm</a> in the programming language dc. The program will print better and better approximations as it runs. But as pi is a transcendental number, the program will continue until interrupted or resource exhaustion of the machine it is run on.
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'_640320[0ksslk3^16lkd12+sk*-lm*lhd1+sh3^/smlxlj*sxll545140134+dsllm*lxlnk/ls+dls!=P]sP3^sj7sn[6sk1ddshsxsm13591409dsllPx10005v426880*ls/K3-k1/pcln14+snlMx]dsMx'</span>
</pre></div>
<p>A fast divide and conquer implementation of the same formula that doubles in size each iteration. It evaluates a finite number if sums as an exact rational number and only performs one large division and square root per iteration. It is fast, but will still quickly slow down as the size of the fraction increases.
</p>
<div class="mw-highlight mw-highlight-lang-bash mw-content-ltr" dir="ltr"><pre>dc<span class="w"> </span>-e<span class="w"> </span><span class="s1">'1Sk1SR13591409dSBSP426880dSQ4/3^9*SC[0r-]s-[lkE*1-k10005vlQ*lP/nAan0k]dSox[Lkd1+Skdd1+Sk3^lC*SQ2*1-d3*d*4-*dSR545140134LB+dSB*lk2%0=-SP]dszx[LRLRdLP*LPLQdLQ*SQ*+SP*SR]sc[d1-d0<yd0<yd0=z0=zlcx]sy0[lcxlox1+lyxllx]dslx'</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Diffie–Hellman_key_exchange">Diffie–Hellman key exchange</h3></div>
<p>A more complex example of dc use embedded in a <a href="Perl" title="Perl">Perl</a> script performs a <a href="Diffie%E2%80%93Hellman_key_exchange" title="Diffie–Hellman key exchange">Diffie–Hellman key exchange</a>. This was popular as a <a href="Signature_block" title="Signature block">signature block</a> among <a href="Cypherpunk" title="Cypherpunk">cypherpunks</a> during the <a href="ITAR" class="mw-redirect" title="ITAR">ITAR</a> debates, where the short script could be run with only Perl and dc, ubiquitous programs on Unix-like operating systems:<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span class="ch">#!/usr/bin/env perl -- -export-a-crypto-system-sig Diffie-Hellman-2-lines</span>
<span class="p">(</span><span class="nv">$g</span><span class="p">,</span><span class="w"> </span><span class="nv">$e</span><span class="p">,</span><span class="w"> </span><span class="nv">$m</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nv">@ARGV</span><span class="p">,</span><span class="w"> </span><span class="nv">$m</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="nb">die</span><span class="w"> </span><span class="s">"$0 gen exp mod\n"</span><span class="p">;</span>
<span class="k">print</span><span class="w"> </span><span class="sb">`echo "16dio1[d2%Sa2/d0<X+d*La1=z\U$m%0]SX$e"[$g*]\EszlXx+p | dc`</span>
</pre></div>
<p>A commented version is slightly easier to understand and shows how to use loops, conditionals, and the <code>q</code> command to return from a macro. With the GNU version of dc, the <code>|</code> command can be used to do arbitrary precision modular exponentiation without needing to write the X function.
</p>
<div class="mw-highlight mw-highlight-lang-perl mw-content-ltr" dir="ltr"><pre><span class="ch">#!/usr/bin/env perl</span>
<span class="k">my</span><span class="w"> </span><span class="p">(</span><span class="nv">$g</span><span class="p">,</span><span class="w"> </span><span class="nv">$e</span><span class="p">,</span><span class="w"> </span><span class="nv">$m</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">map</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">"\U$_"</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="nv">@ARGV</span><span class="p">;</span>
<span class="nb">die</span><span class="w"> </span><span class="s">"$0 gen exp mod\n"</span><span class="w"> </span><span class="k">unless</span><span class="w"> </span><span class="nv">$m</span><span class="p">;</span>
<span class="k">print</span><span class="w"> </span><span class="sb">`echo $g $e $m | dc -e '</span>
<span class="sb"># Hex input and output</span>
<span class="sb">16dio</span>
<span class="sb"># Read m, e and g from stdin on one line</span>
<span class="sb">?SmSeSg</span>
<span class="sb"># Function z: return g * top of stack</span>
<span class="sb">[lg*]sz</span>
<span class="sb"># Function Q: remove the top of the stack and return 1</span>
<span class="sb">[sb1q]sQ</span>
<span class="sb"># Function X(e): recursively compute g^e % m</span>
<span class="sb"># It is the same as Sm^Lm%, but handles arbitrarily large exponents.</span>
<span class="sb"># Stack at entry: e</span>
<span class="sb"># Stack at exit: g^e % m</span>
<span class="sb"># Since e may be very large, this uses the property that g^e % m == </span>
<span class="sb"># if( e == 0 )</span>
<span class="sb"># return 1</span>
<span class="sb"># x = (g^(e/2)) ^ 2</span>
<span class="sb"># if( e % 2 == 1 )</span>
<span class="sb"># x *= g</span>
<span class="sb"># return x %</span>
<span class="sb">[</span>
<span class="sb"> d 0=Q # return 1 if e==0 (otherwise, stack: e)</span>
<span class="sb"> d 2% Sa # Store e%2 in a (stack: e)</span>
<span class="sb"> 2/ # compute e/2</span>
<span class="sb"> lXx # call X(e/2)</span>
<span class="sb"> d* # compute X(e/2)^2</span>
<span class="sb"> La1=z # multiply by g if e%2==1</span>
<span class="sb"> lm % # compute (g^e) % m</span>
<span class="sb">] SX</span>
<span class="sb">le # Load e from the register</span>
<span class="sb">lXx # compute g^e % m</span>
<span class="sb">p # Print the result</span>
<span class="sb">'`</span><span class="p">;</span>
</pre></div>
<div class="mw-heading mw-heading3"><h3 id="Environment_variables">Environment variables</h3></div>
<p>If the <a href="Environment_variable" title="Environment variable">environment variable</a> DC_LINE_LENGTH exists and contains an integer that is greater than 1 and less than <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 2^{16}-1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mn>2</mn>
<mrow class="MJX-TeXAtom-ORD">
<mn>16</mn>
</mrow>
</msup>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle 2^{16}-1}</annotation>
</semantics>
</math></span><img src="./3011c443d1c9945e2c3149776649899dab61c94e.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:7.042ex; height:2.843ex;" alt="{\displaystyle 2^{16}-1}" loading="lazy"></span>, the output of number digits (according to the output base) will be restricted to this value, inserting thereafter backslashes and newlines. The default line length is 70. The special value of 0 disables line breaks.
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Bc_(programming_language)" title="Bc (programming language)">bc (programming language)</a></li>
<li><a href="Calculator_input_methods" title="Calculator input methods">Calculator input methods</a></li>
<li><a href="HP_calculators" title="HP calculators">HP calculators</a></li>
<li><a href="Stack_machine" title="Stack machine">Stack machine</a></li>
<li><a href="Reverse_Polish_notation" title="Reverse Polish notation">Reverse Polish notation</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><span class="neverexpand"><code><a rel="nofollow" class="external text" href="https://linux.die.net/man/1/dc">dc(1)</a></code></span>: an arbitrary precision calculator – <a href="Linux" title="Linux">Linux</a> User Commands <a href="Man_page" title="Man page">Manual</a></span>
</li>
<li id="cite_note-reader-2"><span class="mw-cite-backlink">^ <a href="#cite_ref-reader_2-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-reader_2-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFMcIlroy1987" class="citation techreport cs1"><a href="Doug_McIlroy" class="mw-redirect" title="Doug McIlroy">McIlroy, M. D.</a> (1987). <a rel="nofollow" class="external text" href="http://www.cs.dartmouth.edu/~doug/reader.pdf"><i>A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986</i></a> <span class="cs1-format">(PDF)</span> (Technical report). CSTR. Bell Labs. 139.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20040823221918/http://plan9.bell-labs.com/7thEdMan/vol2/dc">"The sources for the manual page for 7th Edition Unix dc"</a>. Archived from <a rel="nofollow" class="external text" href="http://plan9.bell-labs.com/7thEdMan/vol2/dc">the original</a> on 2004-08-23<span class="reference-accessdate">. Retrieved <span class="nowrap">2004-06-23</span></span>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite id="CITEREFRitchie,_Dennis_M.1979" class="citation web cs1">Ritchie, Dennis M. (Sep 1979). <a rel="nofollow" class="external text" href="http://webarchive.loc.gov/all/20100506231949/http://cm.bell-labs.com/cm/cs/who/dmr/hist.html">"The Evolution of the Unix Timesharing System"</a>. Archived from <a rel="nofollow" class="external text" href="http://cm.bell-labs.com/cm/cs/who/dmr/hist.html">the original</a> on 2010-05-06.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.gnu.org/software/bc/">"GNU bc"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2025-01-25</span></span>.</cite></span>
</li>
<li id="cite_note-KenThompson-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-KenThompson_6-0">^</a></b></span> <span class="reference-text"><cite class="citation audio-visual cs1">Brian Kernighan and Ken Thompson. <a rel="nofollow" class="external text" href="https://www.youtube.com/watch?v=EY6q5dv_B-o"><i>A nerdy delight for any Vintage Computer Fest 2019 attendee: Kernighan interviewing Thompson about Unix</i></a>. YouTube. Event occurs at 29m45s<span class="reference-accessdate">. Retrieved <span class="nowrap">September 3,</span> 2019</span>.</cite></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://tldp.org/LDP/abs/html/mathc.html">"Advanced Bash-Scripting Guide, Chapter 16, Example 16-52 (Factorization)"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-09-20</span></span>.</cite></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><cite id="CITEREFAdam_Back" class="citation web cs1">Adam Back. <a rel="nofollow" class="external text" href="http://www.cypherspace.org/adam/rsa/perl-dh.html">"Diffie–Hellman in 2 lines of Perl"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">5 Jan</span> 2009</span>.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li>Package <a rel="nofollow" class="external text" href="http://packages.debian.org/search?keywords=dc&searchon=names&exact=1&suite=all&section=all">dc</a> in <a href="Debian_GNU/Linux" class="mw-redirect" title="Debian GNU/Linux">Debian GNU/Linux</a> repositories</li>
<li>newest Package <a rel="nofollow" class="external text" href="https://ftp.gnu.org/gnu/bc/bc-1.08.1.tar.xz">GNU bc-1.08.1</a> including dc.</li>
<li><span class="neverexpand"><code><a rel="nofollow" class="external text" href="https://www.mankier.com/1/dc">dc(1)</a></code></span> – <a href="Linux" title="Linux">Linux</a> General Commands <a href="Man_page" title="Man page">Manual</a></li>
<li><span class="neverexpand"><code><a rel="nofollow" class="external text" href="https://9p.io/magic/man2html/1/dc">dc(1)</a></code></span> – <a href="Plan_9_from_Bell_Labs" title="Plan 9 from Bell Labs">Plan 9</a> Programmer's Manual, Volume 1</li>
<li><a rel="nofollow" class="external text" href="https://gnuwin32.sourceforge.net/packages/bc.htm">Native Windows port</a> of <i><a href="Bc_(programming_language)" title="Bc (programming language)">bc</a></i>, which includes dc.</li></ul>
<p><br>
</p>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox" aria-labelledby="Unix_command-line_interface_programs_and_shell_builtins541" style="padding:3px"><table class="nowraplinks mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div id="Unix_command-line_interface_programs_and_shell_builtins541" style="font-size:114%;margin:0 4em"><a href="Unix" title="Unix">Unix</a> <a href="Command-line_interface" title="Command-line interface">command-line interface</a> programs and <a href="Shell_builtin" title="Shell builtin">shell builtins</a></div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%">File system</th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Cat_(Unix)" title="Cat (Unix)">cat</a></li>
<li><a href="Chattr" title="Chattr">chattr</a></li>
<li><a href="Chmod" title="Chmod">chmod</a></li>
<li><a href="Chown" title="Chown">chown</a></li>
<li><a href="Chgrp" title="Chgrp">chgrp</a></li>
<li><a href="Cksum" title="Cksum">cksum</a></li>
<li><a href="Cmp_(Unix)" title="Cmp (Unix)">cmp</a></li>
<li><a href="Cp_(Unix)" title="Cp (Unix)">cp</a></li>
<li><a href="Dd_(Unix)" title="Dd (Unix)">dd</a></li>
<li><a href="Du_(Unix)" title="Du (Unix)">du</a></li>
<li><a href="Df_(Unix)" title="Df (Unix)">df</a></li>
<li><a href="File_(command)" title="File (command)">file</a></li>
<li><a href="Fuser_(Unix)" title="Fuser (Unix)">fuser</a></li>
<li><a href="Ln_(Unix)" title="Ln (Unix)">ln</a></li>
<li><a href="Ls" title="Ls">ls</a></li>
<li><a href="Mkdir" title="Mkdir">mkdir</a></li>
<li><a href="Mv_(Unix)" title="Mv (Unix)">mv</a></li>
<li><a href="Pax_(command)" title="Pax (command)">pax</a></li>
<li><a href="Pwd" title="Pwd">pwd</a></li>
<li><a href="Rm_(Unix)" title="Rm (Unix)">rm</a></li>
<li><a href="Rmdir" title="Rmdir">rmdir</a></li>
<li><a href="Split_(Unix)" title="Split (Unix)">split</a></li>
<li><a href="Tee_(command)" title="Tee (command)">tee</a></li>
<li><a href="Touch_(command)" title="Touch (command)">touch</a></li>
<li><a href="Type_(Unix)" title="Type (Unix)">type</a></li>
<li><a href="Umask" title="Umask">umask</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Processes</th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="At_(command)" title="At (command)">at</a></li>
<li><a href="Job_control_(Unix)#Commands" title="Job control (Unix)">bg</a></li>
<li><a href="Cron" title="Cron">crontab</a></li>
<li><a href="Job_control_(Unix)#Commands" title="Job control (Unix)">fg</a></li>
<li><a href="Kill_(command)" title="Kill (command)">kill</a></li>
<li><a href="Nice_(Unix)" title="Nice (Unix)">nice</a></li>
<li><a href="Ps_(Unix)" title="Ps (Unix)">ps</a></li>
<li><a href="Time_(Unix)" title="Time (Unix)">time</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">User environment</th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Env" title="Env">env</a></li>
<li><a href="Exit_(command)" title="Exit (command)">exit</a></li>
<li><a href="Logname" title="Logname">logname</a></li>
<li><a href="Mesg" title="Mesg">mesg</a></li>
<li><a href="Talk_(software)" title="Talk (software)">talk</a></li>
<li><a href="Tput" title="Tput">tput</a></li>
<li><a href="Uname" title="Uname">uname</a></li>
<li><a href="Who_(Unix)" title="Who (Unix)">who</a></li>
<li><a href="Write_(Unix)" title="Write (Unix)">write</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Text processing</th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="AWK" title="AWK">awk</a></li>
<li><a href="Basename" title="Basename">basename</a></li>
<li><a href="Comm" title="Comm">comm</a></li>
<li><a href="Csplit" title="Csplit">csplit</a></li>
<li><a href="Cut_(Unix)" title="Cut (Unix)">cut</a></li>
<li><a href="Diff" title="Diff">diff</a></li>
<li><a href="Dirname" title="Dirname">dirname</a></li>
<li><a href="Ed_(text_editor)" class="mw-redirect" title="Ed (text editor)">ed</a></li>
<li><a href="Ex_(text_editor)" title="Ex (text editor)">ex</a></li>
<li><a href="Fold_(Unix)" title="Fold (Unix)">fold</a></li>
<li><a href="Head_(Unix)" title="Head (Unix)">head</a></li>
<li><a href="Iconv" title="Iconv">iconv</a></li>
<li><a href="Join_(Unix)" title="Join (Unix)">join</a></li>
<li><a href="M4_(computer_language)" title="M4 (computer language)">m4</a></li>
<li><a href="More_(command)" title="More (command)">more</a></li>
<li><a href="Nl_(Unix)" title="Nl (Unix)">nl</a></li>
<li><a href="Paste_(Unix)" title="Paste (Unix)">paste</a></li>
<li><a href="Patch_(Unix)" title="Patch (Unix)">patch</a></li>
<li><a href="Printf_(Unix)" title="Printf (Unix)">printf</a></li>
<li><a href="Read_(Unix)" title="Read (Unix)">read</a></li>
<li><a href="Sed" title="Sed">sed</a></li>
<li><a href="Sort_(Unix)" title="Sort (Unix)">sort</a></li>
<li><a href="Strings_(Unix)" title="Strings (Unix)">strings</a></li>
<li><a href="Tail_(Unix)" title="Tail (Unix)">tail</a></li>
<li><a href="Tr_(Unix)" title="Tr (Unix)">tr</a></li>
<li><a href="Troff" title="Troff">troff</a></li>
<li><a href="Uniq" title="Uniq">uniq</a></li>
<li><a href="Vi_(text_editor)" title="Vi (text editor)">vi</a></li>
<li><a href="Wc_(Unix)" title="Wc (Unix)">wc</a></li>
<li><a href="Xargs" title="Xargs">xargs</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Shell_builtin" title="Shell builtin">Shell builtins</a></th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Alias_(command)" title="Alias (command)">alias</a></li>
<li><a href="Cd_(command)" title="Cd (command)">cd</a></li>
<li><a href="Echo_(command)" title="Echo (command)">echo</a></li>
<li><a href="Test_(Unix)" title="Test (Unix)">test</a></li>
<li><a href="Environment_variable#unset_command" title="Environment variable">unset</a></li>
<li><a href="Wait_(command)" title="Wait (command)">wait</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Searching</th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Find_(Unix)" title="Find (Unix)">find</a></li>
<li><a href="Grep" title="Grep">grep</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Documentation</th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Man_page" title="Man page">man</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Software_development" title="Software development">Software development</a></th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Ar_(Unix)" title="Ar (Unix)">ar</a></li>
<li><a href="Ctags" title="Ctags">ctags</a></li>
<li><a href="Lex_(software)" title="Lex (software)">lex</a></li>
<li><a href="Make_(software)" title="Make (software)">make</a></li>
<li><a href="Nm_(Unix)" title="Nm (Unix)">nm</a></li>
<li><a href="Strip_(Unix)" title="Strip (Unix)">strip</a></li>
<li><a href="Yacc" title="Yacc">yacc</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Miscellaneous</th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Bc_(programming_language)" title="Bc (programming language)">bc</a></li>
<li><a href="Cal_(command)" title="Cal (command)">cal</a></li>
<li><a href="Expr" title="Expr">expr</a></li>
<li><a href="System_V_printing_system" title="System V printing system">lp</a></li>
<li><a href="Od_(Unix)" title="Od (Unix)">od</a></li>
<li><a href="Sleep_(command)" title="Sleep (command)">sleep</a></li>
<li><a href="True_and_false_(commands)" title="True and false (commands)">true and false</a></li></ul>
</div></td></tr><tr><td class="navbox-abovebelow hlist" colspan="2"><div>
<ul><li><span class="noviewer" typeof="mw:File"><span title="Category"></span></span> <b>Categories</b>
<ul><li>Standard Unix programs</li>
<li>Unix SUS2008 utilities</li></ul></li>
<li><span class="noviewer" typeof="mw:File"><span title="List-Class article"></span></span> <b><a href="List_of_POSIX_commands" title="List of POSIX commands">List</a></b></li></ul>
</div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-04-30" href="https://en.wikipedia.org/wiki/?title=Dc_(computer_program)&oldid=1288100390">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>